#include "CajaChat.h"

CajaChat::CajaChat() {
	this->zonaTexto.set_editable(false);
	this->zonaTexto.set_cursor_visible(false);
	this->venChat.set_shadow_type(Gtk::SHADOW_IN);
	this->venChat.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
	this->venChat.add(this->zonaTexto);
	this->botonEnviar.set_label("Enviar");
	this->botonEnviar.signal_clicked().connect
			(sigc::mem_fun(*this, &CajaChat::enviarTexto));
	this->entradaTexto.signal_activate().connect
			(sigc::mem_fun(*this, &CajaChat::enviarTexto));
	this->pack_end(this->botonEnviar, Gtk::PACK_SHRINK);
	this->pack_end(this->entradaTexto, Gtk::PACK_SHRINK);
	this->pack_end(this->venChat, Gtk::PACK_EXPAND_WIDGET);
}

void CajaChat::enviarTexto() {
	//this->zonaTexto.get_iter_at_location(0, 5);
	std::string entrada = this->entradaTexto.get_text();
	if(entrada != VACIO) {
		entrada.append("\n");
		this->zonaTexto.get_buffer()->insert_at_cursor(entrada);
	}
	Gtk::Adjustment *adj = this->venChat.get_vadjustment();
	adj->set_value(adj->get_upper());
	this->entradaTexto.set_text(VACIO);
}

CajaChat::~CajaChat() {}
